package com.mjk.manager.workflow.component.dto;

import cn.hutool.core.util.ObjectUtil;
import com.yomahub.liteflow.exception.NullParamException;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * bee liteflow 上下文，用于传递上下文参数 获取值/设置值
 */
public class BeeLiteFlowContext {
    private final Map<String, Object> dataMap = new ConcurrentHashMap();

    public BeeLiteFlowContext() {
    }

    public Map<String,Object> getDataMap(){
        return dataMap;
    }

    private  void putDataMap(String key, Object t) {
        if (ObjectUtil.isNull(t)) {
            throw new NullParamException("data can't accept null param");
        } else {
            this.dataMap.put(key, t);
        }
    }

    public boolean hasData(String key) {
        return this.dataMap.containsKey(key);
    }

    public Object getData(String key) {
        return this.dataMap.get(key);
    }

    public  void setData(String key, Object t) {
        this.putDataMap(key, t);
    }
}
